flexarray_t *toremove;
struct libxl_ctx clone;
- if (libxl_clone_context_xs(ctx, &clone)) {
- XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
- return ERROR_NOMEM;
+ if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
+ return -1;
}
toremove = flexarray_make(16, 1);
l1 = libxl_xs_directory(&clone, XBT_NULL, path, &num1);
if (!l1) {
XL_LOG(&clone, XL_LOG_ERROR, "%s is empty", path);
- libxl_discard_cloned_context_xs(&clone);
+ libxl_ctx_free(&clone);
return -1;
}
for (i = 0; i < num1; i++) {
xs_rm(clone.xsh, XBT_NULL, path);
}
flexarray_free(toremove);
- libxl_discard_cloned_context_xs(&clone);
+ libxl_ctx_free(&clone);
return 0;
}
int rc;
struct libxl_ctx clone;
- if (libxl_clone_context_xs(ctx, &clone)) {
- XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
- return ERROR_NOMEM;
+ if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
+ return -1;
}
/* Create strings */
rc = libxl_device_destroy(&clone, backend_path, !wait);
if (rc == -1) {
- libxl_discard_cloned_context_xs(&clone);
+ libxl_ctx_free(&clone);
return ERROR_FAIL;
}
}
xs_rm(clone.xsh, XBT_NULL, hotplug_path);
- libxl_free(&clone, hotplug_path);
- libxl_free(&clone, backend_path);
- libxl_discard_cloned_context_xs(&clone);
+ libxl_ctx_free(&clone);
return 0;
}
return 0;
}
-int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to)
-{
- /* We could just copy the structs, but since
- * maxsize is not a pointer we need to take care
- * of our own GC. */
- *to = *from;
- to->alloc_ptrs = NULL;
- to->alloc_maxsize = 256;
- to->alloc_ptrs = calloc(to->alloc_maxsize, sizeof(void *));
- if (!to->alloc_ptrs)
- return ERROR_NOMEM;
- return 0;
-}
-
-void libxl_discard_cloned_context(struct libxl_ctx *ctx)
-{
- /* We only need to worry about GC-related fields */
- (void)libxl_ctx_free(ctx);
- if (ctx->alloc_ptrs)
- free(ctx->alloc_ptrs);
-}
-
int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr)
{
int i;
char *s;
int rc;
+ if (!ctx->log_callback)
+ return;
+
rc = vasprintf(&s, fmt, ap);
if (rc<0) { s = enomem; goto x; }
int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
/* memory allocation tracking/helpers */
-int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to);
-static inline int libxl_clone_context_xs(
- struct libxl_ctx *from, struct libxl_ctx *to)
-{
- int rc;
- rc = libxl_clone_context(from, to);
- if (rc) return rc;
- to->xsh = xs_daemon_open();
- return 0;
-}
-void libxl_discard_cloned_context(struct libxl_ctx *ctx);
-static inline void libxl_discard_cloned_context_xs(
- struct libxl_ctx *ctx)
-{
- libxl_discard_cloned_context(ctx);
- xs_daemon_close(ctx->xsh);
-}
int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr);
int libxl_free(struct libxl_ctx *ctx, void *ptr);
int libxl_free_all(struct libxl_ctx *ctx);